﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using PBLL;

namespace pufflesweb
{
    public partial class Aregister : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            PModel.Admin myuser = new PModel.Admin();
            
            if (aid.Text.Trim() == "" )
            {
                MessageBox.Show("工号不能为空", "提示");
            }
            else if (aname.Text.Trim() == "")
            {
                MessageBox.Show("姓名不能为空", "提示");
            }
            else if (apassword.Text.Trim() == "")
            {
                MessageBox.Show("密码不能为空", "提示");
            }
            else if (aage.Text.Trim() == "")
            {
                MessageBox.Show("年龄不能为空", "提示");
            }
            else if (ajbo.Text.Trim() == "")
            {
                MessageBox.Show("职位不能为空", "提示");
            }
            else if (Drop.Text.Trim() == "")
            {
                MessageBox.Show("性别不能为空", "提示");
            }
            else
            {
                if (PBLL.Admin.Search(this.aid.Text) == false)
                {
                    MessageBox.Show("工号已存在", "提示");
                }
                else
                {
                    myuser.AID = int.Parse(this.aid.Text);
                    myuser.Aname = this.aname.Text;
                    myuser.Apassword = int.Parse(this.apassword.Text);
                    myuser.Aage = int.Parse(this.aage.Text);
                    myuser.Ajbo = this.ajbo.Text;
                    myuser.Asex = int.Parse(this.Drop.Text);
                    //Response.Redirect("index.aspx");
                    if (PBLL.Admin.add(myuser))
                    {
                        PF.JsHelper.AlertAndParentUrl("添加成功", "main.aspx");
                    }
                    else
                    {
                        PF.JsHelper.AlertAndParentUrl("添加失败,用户名重复，请重新输入", "Aregister.aspx");
                    }
                }

            }
        }
    }
}